package com.jxsm.controller;

import com.jxsm.pojo.Factory;
import com.jxsm.service.FactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * Created by Administrator on 2016/10/30.
 */
@Controller
public class FactoryController {
    @Autowired
    private FactoryService factoryService;

    @RequestMapping("/basicinfo/factory/list.action")
    public String findAll(Map<String ,Object>map){
        map.put("dataList",factoryService.find(null));

        return "/basicinfo/factory/jFactoryList.jsp";
    }
    @RequestMapping("/basicinfo/factory/tocreate.action")
    public String tocreat() {
        return "/basicinfo/factory/jFactoryCreate.jsp";
    }


    @RequestMapping("/basicinfo/factory/insert.action")
    public String insert(Factory factory){
        factoryService.addFactory(factory);
        return "redirect:/basicinfo/factory/list.action";
    }

//    修改厂家信息页面跳转
    @RequestMapping("/basicinfo/factory/toupdate.action")
    public String update( String id,Map<String ,Object>map){
        map.put("factory",factoryService.getFactory(id));
        return "/basicinfo/factory/jFactoryUpdate.jsp";
    }
//    修该厂家的信息
    @RequestMapping("/basicinfo/factory/update.action")
    public String update (Factory factory){
        factoryService.updateFactory(factory);
        return "redirect:/basicinfo/factory/list.action";
    }

//    删除单个厂家信息
    @RequestMapping("/basicinfo/factory/deleteById.action")
    public String deleteById(String id){
        factoryService.deleteById(id);
        return "redirect:/basicinfo/factory/list.action";
    }
//    删除多个厂家信息
    @RequestMapping("/basicinfo/factory/delete.action")
    public  String  delete(@RequestParam("id") String [] id){
        System.out.println(id);
        factoryService.deleteFactory(id);
        return "redirect:/basicinfo/factory/list.action";
    }

    //停用厂家的信息
    @RequestMapping("/basicinfo/factory/stop.action")
    public String stop(@RequestParam("id")String []id){
        factoryService.stop(id);
        return "redirect:/basicinfo/factory/list.action";
    }

    //启用厂家的信息
    @RequestMapping("/basicinfo/factory/start.action")
    public String start(@RequestParam("id")String []id){
        factoryService.start(id);
        return "redirect:/basicinfo/factory/list.action";
    }
}
